package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.operationPeriod.OperationCurVO;
import com.bifang.module.base.common.vo.operationPeriod.OperationPeriodVO;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.base.core.integration.OperationPeriodIntegration;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.ComplaintTypeEnum;
import com.jwsoft.manager.common.enums.NetsignDictEnum;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.common.AreaControlVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignKeyVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignQueryVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolKeyVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentStatus.EduStudentStatusVO;
import com.jwsoft.manager.common.vo.individuation.NetsignSaveVO;
import com.jwsoft.manager.core.dao.model.EduComplaint;
import com.jwsoft.manager.core.dao.model.EduNetsign;
import com.jwsoft.manager.core.dao.model.EduStudentEnrollPre;
import com.jwsoft.manager.core.dao.model.EduhNetsign;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduNetsignIntegration;
import com.jwsoft.manager.core.integration.EduSchoolIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.integration.OperationCacheIntegration;
import com.jwsoft.manager.core.util.EduDesensitizeUtil;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 学校网签合同表业务实现类
 *
 * @author wangtao
 * @since 2022-12-21
 */
@ApiService(funcCode = "eduNetsign", title = "学校网签合同表")
public class EduNetsignIntegrationImpl implements EduNetsignIntegration {

    @Autowired
    public EduNetsignService eduNetsignService;

    @Autowired
    public DictHelper dictHelper;

    @Autowired
    public OperationPeriodIntegration operationPeriodIntegration;
    @Autowired
    public EduSchoolService eduSchoolService;
    @Autowired
    public OperationCacheIntegration operationCacheIntegration;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private CommonIntegration commonIntegration;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduComplaintService eduComplaintService;
    @Autowired
    private RedisHelper redisHelper;
    public static final String APP_WQ_LIMIT = "APP_WQ_LIMIT_";
    public static final String get_wq = "APP_WQ_IDCARD_";
    public static final String get_wqht = "APP_WQ_htbh_";
    @Autowired
    public EduSchoolIntegration eduSchoolIntegration;
    @Autowired
    private DictIntegration dictIntegration;

    @Autowired
    private EduDataTaskDetailService eduDataTaskDetailService;

    @Autowired
    public EduhNetsignService eduhNetsignService;
    public static final String handleTable = "edu_netsign";

    @Override
    @OpApi(funcCode = "eduNetsign0001", title = "学校网签合同表分页查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduNetsignVO> getList(EduNetsignQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        String orgId = vo.getSchoolId();
        if (StringUtils.isBlank(orgId)) {
            orgId = SessionUtil.getOrgId();
        }
        QueryWrapper<EduNetsign> formQueryWrapper = new QueryWrapper<>();
        formQueryWrapper.lambda().eq(EduNetsign::getSchoolId, orgId);
        if(StringUtils.isNotBlank(vo.getIdcard())){
            formQueryWrapper.lambda().eq(EduNetsign::getIdcard, vo.getIdcard());
        }
        if(vo.getYear()!=null){
            formQueryWrapper.lambda().eq(EduNetsign::getYear, vo.getYear());
        }
        if(StringUtils.isNotBlank(vo.getHtbabh())){
            formQueryWrapper.lambda().like(EduNetsign::getHtbabh, vo.getHtbabh());
        }
        if(StringUtils.isNotBlank(vo.getDz())){
            formQueryWrapper.lambda().like(EduNetsign::getDz, vo.getDz());
        }
        if(StringUtils.isNotBlank(vo.getJd())){
            formQueryWrapper.lambda().like(EduNetsign::getJd, vo.getJd());
        }
        if(StringUtils.isNotBlank(vo.getStatus())){
            formQueryWrapper.lambda().eq(EduNetsign::getStatus, vo.getStatus());
        }
        if(StringUtils.isNotBlank(vo.getAreaCode())){
            formQueryWrapper.lambda().eq(EduNetsign::getAreaCode,vo.getAreaCode());
        }
        List<EduNetsign> formList = eduNetsignService.list(formQueryWrapper);
        if (CollectionUtils.isEmpty(formList)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduNetsign> pageInfo = new PageInfo<>(formList);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduNetsignVO> resultList = Convert.toList(EduNetsignVO.class, pageInfo.getList());
        // 转义数据字典值
         dictHelper.valueToName(resultList, Arrays.asList(NetsignDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduNetsign0002", title = "学校网签合同表根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduNetsignVO getById(EduNetsignKeyVO vo) {
        //判断是否迁移过
        EduNetsignVO result;
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), handleTable));
        if (!queryHistoryFlag) {
            EduNetsign entity = eduNetsignService.getById(vo.getNetsignId());
            if (ObjectUtils.isEmpty(entity)) {
                throw new AppException("查询不到详细信息!");
            }
            result = Convert.convert(EduNetsignVO.class, entity);
        }else {
            EduhNetsign eduhNetsign = eduhNetsignService.getById(vo.getNetsignId());
            if (ObjectUtils.isEmpty(eduhNetsign)) {
                throw new AppException("查询不到详细信息!");
            }
            if ("1".equals(eduhNetsign.getEncryptFlag())) {
                if (StringUtils.isNotBlank(eduhNetsign.getIdcard())){
                    eduhNetsign.setIdcard(CommonSecureUtil.sm4Decrypt(eduhNetsign.getIdcard()));
                }
                if (StringUtils.isNotBlank(eduhNetsign.getXm())){
                    eduhNetsign.setXm(CommonSecureUtil.sm4Decrypt(eduhNetsign.getXm()));
                }
                if (StringUtils.isNotBlank(eduhNetsign.getDz())){
                    eduhNetsign.setDz(CommonSecureUtil.sm4Decrypt(eduhNetsign.getDz()));
                }
            }
            result = Convert.convert(EduNetsignVO.class, eduhNetsign);
        }
        return result;
    }
    /** 保存前统一校验*/
    @Override
    @OpApi(funcCode = "eduNetsign0003", title = "学校网签合同表保存前校验", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduNetsignVO vo) {
        //主键为空为新增校验

        //主键不为空为修改校验
    }

    @Override
    @OpApi(funcCode = "eduNetsign0004", title = "学校网签合同表新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduNetsign0004",
            operationName = "学校网签合同表新增",
            dataType = "netsignId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduNetsignVO add(EduNetsignVO vo) {
        //保存前校验
        checkSave(vo);
        List<EduNetsign> list = new ArrayList<>();
        Integer year = vo.getYear();
        if(year==null||year==0){

            vo.setYear(eduHelper.thisYear());
        }
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if(StringUtils.isBlank(vo.getSchoolId())){
            vo.setSchoolId(SessionUtil.getOrgId());
        }
        EduNetsign en = Convert.convert(EduNetsign.class, vo);
        if (!IdcardUtil.isValidCard(vo.getIdcard())) {
            throw new AppException("请输入正确的身份证格式！");
        }
        QueryWrapper<EduNetsign> qw2 = new QueryWrapper<>();
        qw2.lambda()
                .eq(EduNetsign::getYear, vo.getYear())
                .eq(EduNetsign::getHtbabh, vo.getHtbabh())
                .eq(EduNetsign::getIdcard, vo.getIdcard())
                .eq(EduNetsign::getSchoolId,vo.getSchoolId());
        list = eduNetsignService.list(qw2);
        if (list.size() > 0) {
            throw new AppException("已获取到大数据网签数据！");
        }
        QueryWrapper<EduNetsign> qw1 = new QueryWrapper<>();
        qw1.lambda().eq(EduNetsign::getYear, vo.getYear()).eq(EduNetsign::getHtbabh, vo.getHtbabh()).eq(EduNetsign::getSchoolId, vo.getSchoolId()).eq(EduNetsign::getIdcard, vo.getIdcard());
        list = eduNetsignService.list(qw1);
        if (list.size() > 0) {
            throw new AppException("同年度该人员已存在该备案信息！");
        }
        en.setNetsignId(IdUtil.simpleUUID());
        eduNetsignService.save(en);
        //将主键设置回vo使操作日志可以取到
        vo.setNetsignId(en.getNetsignId());
        clearCache(vo.getIdcard());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduNetsign0005", title = "学校网签合同表修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduNetsign0005",
            operationName = "学校网签合同表修改",
            dataType = "netsignId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduNetsignVO edit(EduNetsignVO vo) {
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(Integer.valueOf(vo.getYear()), handleTable));
        if (queryHistoryFlag) {
            throw new AppException("历史数据无法修改");
        }
        if(StringUtils.isBlank(vo.getNetsignId())){
            throw new AppException("需要修改的网签id不能为空");
        }
        List<EduNetsign> list = new ArrayList<>();
        EduNetsign old=eduNetsignService.getById(vo.getNetsignId());
        if(old==null){
            throw new AppException("不存在需要修改的网签数据");
        }
        EduNetsign en = Convert.convert(EduNetsign.class, vo);
        en.setNetsignId(old.getNetsignId());
        en.setSchoolId(old.getSchoolId());
        if (!IdcardUtil.isValidCard(vo.getIdcard())) {
            throw new AppException("请输入正确的身份证格式！");
        }
        QueryWrapper<EduNetsign> qw1 = new QueryWrapper<>();
        qw1.lambda().eq(EduNetsign::getYear, en.getYear()).eq(EduNetsign::getHtbabh, vo.getHtbabh()).eq(EduNetsign::getSchoolId, en.getSchoolId()).eq(EduNetsign::getIdcard, vo.getIdcard())
                .ne(EduNetsign::getNetsignId,en.getNetsignId());
        list = eduNetsignService.list(qw1);
        if (list.size() > 0) {
            throw new AppException("同年度该人员已存在该备案信息！");
        }
        QueryWrapper<EduNetsign> qw2 = new QueryWrapper<>();
        qw2.lambda().eq(EduNetsign::getYear, en.getYear()).eq(EduNetsign::getHtbabh, vo.getHtbabh()).eq(EduNetsign::getIdcard, en.getIdcard()).isNull(EduNetsign::getSchoolId)
                .ne(EduNetsign::getNetsignId,en.getNetsignId());
        list = eduNetsignService.list(qw2);
        if (list.size() > 0) {
            throw new AppException("已获取到大数据网签数据！");
        }
        eduNetsignService.saveOrUpdate(en);
        clearCache(vo.getIdcard());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduNetsign0006", title = "学校网签合同表根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "eduNetsign0006",
            operationName = "学校网签合同表删除",
            dataType = "netsignId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduNetsignKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getNetsignId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduNetsign entity = eduNetsignService.getById(vo.getNetsignId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduNetsignService.removeById(vo.getNetsignId());
        clearCache(entity.getIdcard());
    }
    //清除缓存
    private void clearCache(String idcard){
        //查询人员
        if(StringUtils.isBlank(idcard)){
            return;
        }

        QueryWrapper<EduStudentEnrollPre> queryPreWrapper=new QueryWrapper<>();
        queryPreWrapper.lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getMotherIdcard)
                .eq(EduStudentEnrollPre::getYear,eduHelper.thisYear())
                .and( wrapper -> {
                    wrapper.eq(EduStudentEnrollPre::getIdcard, idcard)
                            .or()
                            .eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                            .or()
                            .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                });
        List<EduStudentEnrollPre> list=eduStudentEnrollPreService.list(queryPreWrapper);
        if (CollectionUtils.isEmpty(list)){
            return;
        }
        for (EduStudentEnrollPre pre:list) {
            //网签
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
        }
    }
    @Override
    @OpApi(funcCode = "eduNetsign0007", title = "根据身份证获取网签信息并保存", funcType = FuncTypeEnum.query)
    public List<EduNetsignVO> getNetsignAndSave(NetsignSaveVO vo) {
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        ApiModel apiModel=eduHelper.getEduFunc("saveNetsignInterfaceData",vo.getAreaCode());
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                List<EduNetsignVO> list= (List<EduNetsignVO>) apiModel.getMethod().invoke(bean, vo);
                if(!CollectionUtils.isEmpty(list)){

                    return list;
                }
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
        return new ArrayList<>();
    }

    @Override
    @OpApi(funcCode = "eduNetsign0013", title = "根据购房合同获取网签信息并保存金华共享接口", funcType = FuncTypeEnum.query)
    public List<EduNetsignVO> getNetsignAndSaveJh(NetsignSaveVO vo) {
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        ApiModel apiModel=eduHelper.getEduFunc("saveNetsignJhInterfaceData",vo.getAreaCode());
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                List<EduNetsignVO> list= (List<EduNetsignVO>) apiModel.getMethod().invoke(bean, vo);
                if(!CollectionUtils.isEmpty(list)){

                    return list;
                }
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
        return new ArrayList<>();
    }

    @Override
    @OpApi(funcCode = "eduNetsign0008", title = "家长端获取网签信息并保存", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE,savelog = false)
    public List<EduNetsignVO> getAppNetsignAndSave(NetsignSaveVO vo) {
        String idcard=vo.getIdcard();
        boolean flag=false;
        if(StringUtils.isBlank(idcard)){
            idcard=SessionUtil.getSessionInfo().getIdcard();
            flag=true;
        }

        //同一身份证一天最多同步获取3次
        String key = get_wq+idcard;
        Integer getCount= (Integer) redisHelper.get(key);
        if(getCount==null||getCount==0){
            getCount=1;
        }else{
            getCount=getCount+1;
        }
        redisHelper.set(key,getCount,43200);
        if(getCount>3){
            throw new AppException("24小时内最多获取三次，如还有问题，请致电联系");
        }
        Object maxObj = redisHelper.get(APP_WQ_LIMIT + DateUtil.today());
        int max;
        if (org.springframework.util.ObjectUtils.isEmpty(maxObj)) {
            redisHelper.set(APP_WQ_LIMIT + DateUtil.today(), 1);
            max = 1;
        } else {
            max = (int) redisHelper.get(APP_WQ_LIMIT + DateUtil.today());
            max++;
            redisHelper.set(APP_WQ_LIMIT + DateUtil.today(), max);
        }
        CommonVO commonVO=new CommonVO();
        commonVO.setParamKey("APP_WQ_LIMIT");
        String limit = commonIntegration.getValueByKey(commonVO);
        if (!org.springframework.util.ObjectUtils.isEmpty(limit) && max > Integer.parseInt(limit)) {
            throw new AppException("今日大数据接口已达上限，请明日再试！");
        }
        List<EduNetsignVO> retList=new ArrayList<>();
        Integer year = operationCacheIntegration.getPeriodYear().getYear();
        final String finalId=idcard;
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherName,EduStudentEnrollPre::getMotherIdcard)
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getFatherIdcard, finalId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, finalId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, finalId);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        if(flag){
            if(CollectionUtils.isEmpty(queryList)){
                return new ArrayList<>();
            }
            List<String> idcardList=new ArrayList<>();

            for(EduStudentEnrollPre eduStudentEnrollPre:queryList){
                if(StringUtils.isNotBlank(eduStudentEnrollPre.getIdcard())&&!idcardList.contains(eduStudentEnrollPre.getIdcard())){
                    idcardList.add(eduStudentEnrollPre.getIdcard());
                    NetsignSaveVO saveVO=new NetsignSaveVO();
                    saveVO.setIdcard(eduStudentEnrollPre.getIdcard());
                    saveVO.setName(eduStudentEnrollPre.getFullName());
                    saveVO.setReplaceFlag(true);
                    retList.addAll(getNetsignAndSave(saveVO));
                }
                if(StringUtils.isNotBlank(eduStudentEnrollPre.getFatherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getFatherIdcard())){
                    idcardList.add(eduStudentEnrollPre.getFatherIdcard());
                    NetsignSaveVO saveVO=new NetsignSaveVO();
                    saveVO.setIdcard(eduStudentEnrollPre.getFatherIdcard());
                    saveVO.setName(eduStudentEnrollPre.getFatherName());
                    saveVO.setReplaceFlag(true);
                    retList.addAll(getNetsignAndSave(saveVO));
                }
                if(StringUtils.isNotBlank(eduStudentEnrollPre.getMotherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getMotherIdcard())){
                    idcardList.add(eduStudentEnrollPre.getMotherIdcard());
                    NetsignSaveVO saveVO=new NetsignSaveVO();
                    saveVO.setIdcard(eduStudentEnrollPre.getMotherIdcard());
                    saveVO.setName(eduStudentEnrollPre.getMotherName());
                    saveVO.setReplaceFlag(true);
                    retList.addAll(getNetsignAndSave(saveVO));
                }
            }
        }else{
            NetsignSaveVO saveVO=new NetsignSaveVO();
            saveVO.setIdcard(vo.getIdcard());
            saveVO.setName(vo.getName());
            saveVO.setReplaceFlag(true);
            retList.addAll(getNetsignAndSave(saveVO));
        }
        if(!CollectionUtils.isEmpty(queryList)){
            EduStudentEnrollPre pre=queryList.get(0);
            if(StringUtils.isNotBlank(pre.getIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getIdcard());
            }
            if(StringUtils.isNotBlank(pre.getFatherIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getFatherIdcard());
            }
            if(StringUtils.isNotBlank(pre.getMotherIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getMotherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getMotherIdcard());
            }
            for(EduStudentEnrollPre studentEnrollPre:queryList){
                eduEnrollClearCacheHelper.clearCachePreBefore(studentEnrollPre.getStudentEnrollPreId());
            }

        }
        return retList;
    }

    @Override
    @OpApi(funcCode = "eduNetsign0012", title = "根据合同编号获取网签信息家长端", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE,savelog = false)
    public List<EduNetsignVO> getAppNetsignAndSaveJh(NetsignSaveVO vo) {
        if(StringUtils.isBlank(vo.getHtbh())){
            throw new AppException("合同编号不能为空");
        }
        if(StringUtils.isBlank(vo.getType())){
            throw new AppException("类型不能为空");
        }

        String idcard=SessionUtil.getSessionInfo().getIdcard();
        if(StringUtils.isBlank(idcard)){
            throw new AppException("请先登录系统后再获取");
        }


        List<EduNetsignVO> retList=new ArrayList<>();
        Integer year = operationCacheIntegration.getPeriodYear().getYear();
        final String finalId=idcard;
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherName,EduStudentEnrollPre::getMotherIdcard)
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getFatherIdcard, finalId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, finalId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, finalId);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);

        if(!CollectionUtils.isEmpty(queryList)){
            EduStudentEnrollPre pre=queryList.get(0);
            //获取招生配置参数
            EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
            queryVO.setClassify("2");
            if(StringUtils.isBlank(vo.getAreaCode())){
                pre.setAreaCode(pre.getAreaCode());
            }else{
                queryVO.setAreaCode(vo.getAreaCode());
            }
            queryVO.setYear(pre.getYear());
            EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
            if(eduOperationCacheVO==null){
                throw new AppException("本年度暂未开放网签（购房）合同核验");
            }
            Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
            EduOperationCacheDetailVO wqOperation=operation.get("YW050");
            if(!wqOperation.isFlag()){
                throw new AppException("本年度暂未开放网签（购房）合同核验");
            }
            //同一身份证一天最多同步获取3次
            String key = get_wq+idcard;
            Integer getCount= (Integer) redisHelper.get(key);
            if(getCount==null||getCount==0){
                getCount=1;
            }else{
                getCount=getCount+1;
            }
            redisHelper.set(key,getCount,43200);
            if(getCount>6){
                throw new AppException("24小时内最多获取6次，请明天再试，如还有问题，请致电联系");
            }
            Object maxObj = redisHelper.get(APP_WQ_LIMIT + DateUtil.today());
            int max;
            if (org.springframework.util.ObjectUtils.isEmpty(maxObj)) {
                redisHelper.set(APP_WQ_LIMIT + DateUtil.today(), 1);
                max = 1;
            } else {
                max = (int) redisHelper.get(APP_WQ_LIMIT + DateUtil.today());
                max++;
                redisHelper.set(APP_WQ_LIMIT + DateUtil.today(), max);
            }
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("APP_WQ_LIMIT");
            String limit = commonIntegration.getValueByKey(commonVO);
            if (!org.springframework.util.ObjectUtils.isEmpty(limit) && max > Integer.parseInt(limit)) {
                throw new AppException("今日大数据接口已达上限，请明日再试！");
            }
            vo.setReplaceFlag(true);
            retList.addAll(getNetsignAndSaveJh(vo));

            if(StringUtils.isNotBlank(pre.getIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getIdcard());
            }
            if(StringUtils.isNotBlank(pre.getFatherIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getFatherIdcard());
            }
            if(StringUtils.isNotBlank(pre.getMotherIdcard())){
                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(pre.getMotherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(pre.getMotherIdcard());
            }
            for(EduStudentEnrollPre studentEnrollPre:queryList){
                eduEnrollClearCacheHelper.clearCachePreBefore(studentEnrollPre.getStudentEnrollPreId());
            }

        }else{
            throw new AppException("本年度未匹配到可就读的子女信息，不能核验，请先登记子女信息");
        }
        return retList;
    }

    @Override
    @OpApi(funcCode = "eduNetsign0009", title = "家长端获取我的网签信息", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE,savelog = false)
    public List<EduNetsignVO> getAppNetsignList(AreaControlVO vo) {

        String idcard=SessionUtil.getSessionInfo().getIdcard();
        if(StringUtils.isBlank(idcard)){
            throw new AppException("用户的证件号码不能为空");
        }
        String key=idcard;
        Cache<String, List<EduNetsignVO>> cache = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_WQ, CacheType.BOTH, Duration.ofHours(6), Duration.ofSeconds(20));
        List<EduNetsignVO> value=  cache.get(key);
        if(value!=null){
            return value;
        }
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        EduOperationCacheQueryVO queryOpVO=new EduOperationCacheQueryVO();
        queryOpVO.setOperating("YW052");
        queryOpVO.setAreaCode(vo.getAreaCode());
        queryOpVO.setClassify("2");
        EduOperationCacheDetailVO wqOption=eduSystemConfigIntegration.getEduOperationOne(queryOpVO);
        int year=wqOption.getYear();
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda()
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        if(CollectionUtils.isEmpty(queryList)){
            return new ArrayList<>();
        }
        List<String> idcardList=new ArrayList<>();
        for(EduStudentEnrollPre eduStudentEnrollPre:queryList){
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getIdcard())&&!idcardList.contains(eduStudentEnrollPre.getIdcard())){
                idcardList.add(eduStudentEnrollPre.getIdcard());
            }
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getFatherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getFatherIdcard())){
                idcardList.add(eduStudentEnrollPre.getFatherIdcard());
            }
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getMotherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getMotherIdcard())){
                idcardList.add(eduStudentEnrollPre.getMotherIdcard());
            }
        }
        QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
        netsignQueryWrapper.lambda().eq(EduNetsign::getYear, year)
                .eq(EduNetsign::getAreaCode, vo.getAreaCode())
                .in(EduNetsign::getIdcard, idcardList).orderByAsc(EduNetsign::getIdcard);
        List<EduNetsign> netsignList = eduNetsignService.list(netsignQueryWrapper);
        if (!CollectionUtils.isEmpty(netsignList)) {
            List<EduNetsignVO> eduNetsignVOList = new ArrayList<>();
            for(EduNetsign eduNetsign:netsignList) {
                EduNetsignVO eduNetsignVO = Convert.convert(EduNetsignVO.class, eduNetsign);
                if(StringUtils.isNotBlank(eduNetsign.getBasj())){
                    Integer basj=0;
                    try {
                        Date basjDate = DateUtil.parse(eduNetsign.getBasj());
                        basj=Integer.parseInt(DateUtil.format(basjDate,"YYYYMMDD"));
                    }catch (Exception e){
                        basj=Integer.parseInt(eduNetsign.getBasj().replaceAll("-","").replaceAll("/","").substring(0,8));
                    }

                    if(wqOption.getBegTime()!=null){
                        Integer begTime=Integer.parseInt(DateUtil.format(wqOption.getBegTime(),"YYYYMMDD"));
                        if(basj<begTime){
                            continue;
                        }
                    }
                    if(wqOption.getEndTime()!=null){
                        Integer endTime=Integer.parseInt(DateUtil.format(wqOption.getEndTime(),"YYYYMMDD"));
                        if(basj>endTime){
                            continue;
                        }
                    }
                }
                QueryWrapper<EduComplaint> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().select(EduComplaint::getHandleStatus).eq(EduComplaint::getType, ComplaintTypeEnum.sb.getType())
                        .eq(EduComplaint::getHandleStatus,BoolEnum.FALSE.getType())
                        .eq(EduComplaint::getOtherId,eduNetsign.getNetsignId());
                List<EduComplaint> complaints=eduComplaintService.list(queryWrapper);
                if(!CollectionUtils.isEmpty(complaints)){
                    eduNetsignVO.setWqHandleStatus(complaints.get(0).getHandleStatus());
                }
                if(StringUtils.isNotBlank(eduNetsignVO.getSchoolId())){
                    EduSchoolVO eduSchool=eduSchoolService.getDetail(eduNetsignVO.getSchoolId());
                    if(eduSchool!=null){
                        eduNetsignVO.setSchoolName(eduSchool.getSchoolName());
                    }
                }
                eduNetsignVOList.add(eduNetsignVO);
            }
            cache.put(key,eduNetsignVOList);
            return eduNetsignVOList;
        }
        cache.put(key,new ArrayList<>());
        return new ArrayList<>();
    }

    @Override
    @OpApi(funcCode = "eduNetsign0010", title = "管理员分页查询学校网签合同表信息", funcType = FuncTypeEnum.query)
    public PageInfo<EduNetsignVO> getListAdmin(EduNetsignQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        List<String> areaCodeList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            List<SelectVO> selectVOList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            areaCodeList = selectVOList.stream()
                    .map(SelectVO::getDictKey)
                    .collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaCodeList.contains(sessionAreaCode)) {
                areaCodeList.add(sessionAreaCode);
            }
        } else {
            areaCodeList.add(vo.getAreaCode());
        }
        if (CollectionUtils.isEmpty(areaCodeList)) {
            throw new AppException("必须传入行政区划");
        }
        //取出脱敏字段，判断是否为空
        Boolean desensitizeFlag = vo.getDesensitizeFlag();
        if (desensitizeFlag == null) {
            desensitizeFlag = true;
        }
        //根据任务判断是否当前年度处理过迁移数据
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), handleTable);
        if (!queryHistoryFlag) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            QueryWrapper<EduNetsign> formQueryWrapper = new QueryWrapper<>();
            formQueryWrapper.lambda().in(EduNetsign::getAreaCode, areaCodeList);
//        formQueryWrapper.lambda().eq(EduNetsign::getSchoolId, orgId);
            if (StringUtils.isNotBlank(vo.getIdcard())) {
                formQueryWrapper.lambda().eq(EduNetsign::getIdcard, vo.getIdcard());
            }
            if (vo.getYear() != null) {
                formQueryWrapper.lambda().eq(EduNetsign::getYear, vo.getYear());
            } else {
                int year = eduHelper.thisYear();
                formQueryWrapper.lambda().eq(EduNetsign::getYear, year);
            }
            if (StringUtils.isNotBlank(vo.getHtbabh())) {
                formQueryWrapper.lambda().like(EduNetsign::getHtbabh, vo.getHtbabh());
            }
            if (StringUtils.isNotBlank(vo.getDz())) {
                formQueryWrapper.lambda().like(EduNetsign::getDz, vo.getDz());
            }
            if (StringUtils.isNotBlank(vo.getJd())) {
                formQueryWrapper.lambda().like(EduNetsign::getJd, vo.getJd());
            }
            if (StringUtils.isNotBlank(vo.getStatus())) {
                formQueryWrapper.lambda().eq(EduNetsign::getStatus, vo.getStatus());
            }
            List<EduNetsign> formList = eduNetsignService.list(formQueryWrapper);
            if (CollectionUtils.isEmpty(formList)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            PageInfo<EduNetsign> pageInfo = new PageInfo<>(formList);
            // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
            List<EduNetsignVO> resultList = Convert.toList(EduNetsignVO.class, pageInfo.getList());
            EduSchoolKeyVO schoolVo = new EduSchoolKeyVO();
            for (EduNetsignVO resultOne : resultList) {
                if (resultOne.getSchoolId() != null && !resultOne.getSchoolId().equals("")) {
                    schoolVo.setOrgId(resultOne.getSchoolId());
                    try {
                        EduSchoolVO eduscool = eduSchoolIntegration.getById(schoolVo);
                        resultOne.setSchoolName(eduscool.getSchoolName());
                    } catch (AppException e) {
                        //学校编码错误，则返回空值。学校getById方法，无数据会抛出异常“查询不到详细信息!”
                    }
                }
            }
            // 转义数据字典值
            dictHelper.valueToName(resultList, Arrays.asList(NetsignDictEnum.values()));
            if (desensitizeFlag) {
                for (EduNetsignVO eduNetsignVO : resultList) {
                    eduNetsignVO.setIdcard(EduDesensitizeUtil.desensitizeIdcard(eduNetsignVO.getIdcard()));
                    eduNetsignVO.setXm(EduDesensitizeUtil.desensitizeFullName(eduNetsignVO.getXm()));
                    eduNetsignVO.setDz(EduDesensitizeUtil.desensitizeAddress(eduNetsignVO.getDz()));
                }
            }
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        } else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTable));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                if (StringUtils.isNotBlank(vo.getIdcard())){
                    vo.setIdcard(CommonSecureUtil.sm4Encrypt(vo.getIdcard()));
                }
                if (StringUtils.isNotBlank(vo.getXm())){
                    vo.setXm(CommonSecureUtil.sm4Encrypt(vo.getXm()));
                }
                if (StringUtils.isNotBlank(vo.getDz())){
                    vo.setDz(CommonSecureUtil.sm4Encrypt(vo.getDz()));
                }
            }
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            QueryWrapper<EduhNetsign> formQueryWrapper = new QueryWrapper<>();
            formQueryWrapper.lambda().in(EduhNetsign::getAreaCode, areaCodeList);
//        formQueryWrapper.lambda().eq(EduNetsign::getSchoolId, orgId);
            if (StringUtils.isNotBlank(vo.getIdcard())) {
                formQueryWrapper.lambda().eq(EduhNetsign::getIdcard, vo.getIdcard());
            }
            if (vo.getYear() != null) {
                formQueryWrapper.lambda().eq(EduhNetsign::getYear, vo.getYear());
            } else {
                int year = eduHelper.thisYear();
                formQueryWrapper.lambda().eq(EduhNetsign::getYear, year);
            }
            if (StringUtils.isNotBlank(vo.getHtbabh())) {
                formQueryWrapper.lambda().like(EduhNetsign::getHtbabh, vo.getHtbabh());
            }
            if (StringUtils.isNotBlank(vo.getDz())) {
                formQueryWrapper.lambda().like(EduhNetsign::getDz, vo.getDz());
            }
            if (StringUtils.isNotBlank(vo.getJd())) {
                formQueryWrapper.lambda().like(EduhNetsign::getJd, vo.getJd());
            }
            if (StringUtils.isNotBlank(vo.getStatus())) {
                formQueryWrapper.lambda().eq(EduhNetsign::getStatus, vo.getStatus());
            }
            List<EduhNetsign> formList = eduhNetsignService.list(formQueryWrapper);
            if (CollectionUtils.isEmpty(formList)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            PageInfo<EduhNetsign> pageInfo = new PageInfo<>(formList);
            // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
            List<EduNetsignVO> resultList = Convert.toList(EduNetsignVO.class, pageInfo.getList());
            EduSchoolKeyVO schoolVo = new EduSchoolKeyVO();
            for (EduNetsignVO resultOne : resultList) {
                if ("1".equals(resultOne.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(resultOne.getIdcard())){
                        resultOne.setIdcard(CommonSecureUtil.sm4Decrypt(resultOne.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(resultOne.getXm())){
                        resultOne.setXm(CommonSecureUtil.sm4Decrypt(resultOne.getXm()));
                    }
                    if (StringUtils.isNotBlank(resultOne.getDz())){
                        resultOne.setDz(CommonSecureUtil.sm4Decrypt(resultOne.getDz()));
                    }
                }
                if (resultOne.getSchoolId() != null && !resultOne.getSchoolId().equals("")) {
                    schoolVo.setOrgId(resultOne.getSchoolId());
                    try {
                        EduSchoolVO eduscool = eduSchoolIntegration.getById(schoolVo);
                        resultOne.setSchoolName(eduscool.getSchoolName());
                    } catch (AppException e) {
                        //学校编码错误，则返回空值。学校getById方法，无数据会抛出异常“查询不到详细信息!”
                    }
                }
            }
            // 转义数据字典值
            dictHelper.valueToName(resultList, Arrays.asList(NetsignDictEnum.values()));
            if (desensitizeFlag) {
                for (EduNetsignVO eduNetsignVO : resultList) {
                    eduNetsignVO.setIdcard(EduDesensitizeUtil.desensitizeIdcard(eduNetsignVO.getIdcard()));
                    eduNetsignVO.setXm(EduDesensitizeUtil.desensitizeFullName(eduNetsignVO.getXm()));
                    eduNetsignVO.setDz(EduDesensitizeUtil.desensitizeAddress(eduNetsignVO.getDz()));
                }
            }
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        }
    }


    @Override
    @OpApi(funcCode = "eduNetsign0011", title = "管理员网签合同表新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduNetsign0011",
            operationName = "学校网签合同表新增",
            dataType = "netsignId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduNetsignVO addAdmin(EduNetsignVO vo) {
        //保存前校验
        checkSave(vo);
        List<EduNetsign> list = new ArrayList<>();
        Integer year = vo.getYear();
        if(year==null||year==0){
            OperationCurVO curVO = new OperationCurVO();
            curVO.setOperating("XN");
            OperationPeriodVO operationPeriodVO =
                    operationPeriodIntegration.getCurrentByOperating(curVO);
            if (operationPeriodVO != null) {
                year = operationPeriodVO.getPeriodYear();
            } else {
                year = DateUtil.thisYear();
            }
            vo.setYear(year);
        }
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
//        if(SpecialStringUtils.isBlank(vo.getSchoolId())){
//            vo.setSchoolId(SessionUtil.getOrgId());
//        }
        EduNetsign en = Convert.convert(EduNetsign.class, vo);
        if (!IdcardUtil.isValidCard(vo.getIdcard())) {
            throw new AppException("请输入正确的身份证格式！");
        }
        QueryWrapper<EduNetsign> qw2 = new QueryWrapper<>();
        qw2.lambda().eq(EduNetsign::getYear, vo.getYear()).eq(EduNetsign::getHtbabh, vo.getHtbabh()).eq(EduNetsign::getIdcard, vo.getIdcard()).isNull(EduNetsign::getSchoolId);
        list = eduNetsignService.list(qw2);
        if (list.size() > 0) {
            throw new AppException("已获取到大数据网签数据！");
        }
        QueryWrapper<EduNetsign> qw1 = new QueryWrapper<>();
        qw1.lambda().eq(EduNetsign::getYear, vo.getYear()).eq(EduNetsign::getHtbabh, vo.getHtbabh()).eq(EduNetsign::getSchoolId, vo.getSchoolId()).eq(EduNetsign::getIdcard, vo.getIdcard());
        list = eduNetsignService.list(qw1);
        if (list.size() > 0) {
            throw new AppException("同年度该人员已存在该备案信息！");
        }
        en.setNetsignId(IdUtil.simpleUUID());
        eduNetsignService.save(en);
        //将主键设置回vo使操作日志可以取到
        vo.setNetsignId(en.getNetsignId());
        clearCache(vo.getIdcard());
        return vo;
    }


}
